#!/usr/bin/python

###############################
## A base function for plots ##
###############################

#######################################################      
## Set PyRoot Environment and PlotConfig Path first ###
#######################################################
import sys
ROOTSYS = '/afs/atlas.umich.edu/opt/root/lib'
sys.path.append(ROOTSYS)
PlotConfig='../'
PlotConfig2='.'
sys.path.append(PlotConfig)
sys.path.append(PlotConfig2)

#####################
## Import Module  ###
#####################
import array
import os
import glob
from math import sqrt,fabs,sin
from ROOT import TFile,TTree,TChain,TBranch,TH1,TH1F,TList
from ROOT import TLorentzVector
from ROOT import THStack,TCanvas,TLegend,TColor,TPaveText
from ROOT import gStyle,gDirectory

####################
## Import Template #
####################
from plot_template import plot_template
from plot_template_4lep import plot_template_combined

###############
## Plotting ###
###############
RatioSize=-0.2
RatioErr=1
RatioMin,RatioMax=0.5,1.5
RatioAdj=-1

ShowMCErr=-1
MCErree=0.03157
MCErrmm=0.01276
MCErrll=0.01584

plot_config='plot_configure'


#ATLAS='ATLAS For Approval'
ATLAS=''
figFormat='all'

yscale=2

####### TrigMatch, MZ1
histoDir='CaloIpIso'
##### d0 sig
Mmin, Mmax=-10, 10
Rebin=25
binSize=Rebin*0.02
Events=str('Events / %.1f' % binSize)
hname=histoDir+'_eeee_SF_Lepd0sig'
hxt='d_{0}sig'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)

hname=histoDir+'_mmmm_SF_Lepd0sig'
hxt='d_{0}sig'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)

##### z0
Mmin, Mmax=-10, 10
Rebin=25
binSize=Rebin*0.02
Events=str('Events / %.1f' % binSize)
hname=histoDir+'_eeee_SF_Lepz0'
hxt='z_{0} [mm]'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)

hname=histoDir+'_mmmm_SF_Lepz0'
hxt='z_{0} [mm]'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)

##### CaloIso
Mmin, Mmax=0, 2
Rebin=5
binSize=Rebin*0.02
Events=str('Events / %.2f' % binSize)
hname=histoDir+'_eeee_SF_LepCaloIso'
hxt='E_{T}cone20/E_{T}'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)

hname=histoDir+'_mmmm_SF_LepCaloIso'
hxt='E_{T}cone20/E_{T}'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)

##### TrkIso
Mmin, Mmax=0, 2
Rebin=5
binSize=Rebin*0.02
Events=str('Events / %.2f' % binSize)
hname=histoDir+'_eeee_SF_LepTrkIso'
hxt='p_{T}cone20/p_{T}'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)

hname=histoDir+'_mmmm_SF_LepTrkIso'
hxt='p_{T}cone20/p_{T}'
plot_template_combined(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat)
